package com.liuyk.commonlib.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.liuyk.commonlib.R;

/**
 * DESC
 * <p>
 * Created by liuyakui on 2020/7/22.
 */
public class OtherDialogUtils {

    private static Dialog mLoadingDialog;

    public static Dialog createProgressDialog(Context context, String message) {
        View layout = LayoutInflater.from(context).inflate(R.layout.progress_toast_style, null);
        TextView textView = layout.findViewById(R.id.tv_progressbar_toast_hint);
        textView.setText(message);

        Dialog progressDialog = new Dialog(context, R.style.TransparentDialog);
        progressDialog.setContentView(layout, new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        return progressDialog;
    }

    public static void showLoading(Activity context, String message) {
        try {
            if (mLoadingDialog == null) {
                mLoadingDialog = createProgressDialog(context, message);
                mLoadingDialog.setCancelable(true);
            }
            if (!mLoadingDialog.isShowing() && !context.isFinishing() && !context.isDestroyed()) {
                mLoadingDialog.show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void dismissLoading() {
        try {
            if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
                mLoadingDialog.dismiss();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            mLoadingDialog = null;
        }
    }

    //日志
    public static void showNetworkLog(Activity activity, String jsonText, String url, String header, String ps) {
        String content = "url \n" + url + "\nheader \n" + header + "\n报文 \n" + ps;

//        DebugLogDialog dialog = new DebugLogDialog(activity);
//        dialog.setTitleText("网络日志");
//        dialog.setContentText(content);
//        dialog.setPositiveText("关闭");
//        dialog.setNeutralText("复制");
//        dialog.setNeutralClickListener(new BaseDialog.NeutralClickListener() {
//            @Override
//            public void neutral(View view) {
//                CommonUtils.copyText(App.context, content + "\n" + jsonText);
//            }
//        });
//        dialog.setData(jsonText);
//        dialog.show();
    }
}
